package NC;

public class NC11 {
    public TreeNode sortedArrayToBST (int[] nums) {
        // write code here
        if(nums==null||nums.length==0) return null;
        return subToBST(nums,0,nums.length-1);


    }
    public TreeNode subToBST(int[] nums,int left,int right){
        if(left>right) return null;
        if(left==right) return new TreeNode(nums[left]);
        int mid = left + (right-left+1)/2; // 这里必须是+1
        TreeNode root = new TreeNode(nums[mid]);
        root.left = subToBST(nums,left,mid-1);
        root.right = subToBST(nums,mid+1,right);
        return root;
    }
}
